package com.example.redisstudy1.service;

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.BoundSetOperations;
import org.springframework.data.redis.core.RedisTemplate;

import javax.annotation.Resource;
import java.util.Set;

@SpringBootTest
public class set1 {


    @Resource
    private RedisTemplate<String,Object> redisTemplate;

    @Test
    void add(){
        BoundSetOperations<String, Object> setOps = redisTemplate.boundSetOps("demo-set");
        for (int i = 0; i < 20; i++) {
            setOps.add(i);
        }
    }

    @Test
    void get1(){
        BoundSetOperations<String, Object> setOps = redisTemplate.boundSetOps("demo-set");

        Set<Object> members = setOps.members();
        System.out.println(members);
        System.out.println(setOps.isMember(12));
        System.out.println(setOps.randomMembers(2));
        System.out.println(setOps.randomMembers(2));

        //无序弹出
        System.out.println( redisTemplate.opsForSet().pop("demo-set",2));

//        redisTemplate.opsForSet()
    }
}
